from Common.basePage import BasePage
from Configs.env import Env

class LoginPage(BasePage):
    '''
    0. 打开门户登录页面
    1. 登录
    '''
    def open_hx_loginpage(self,url=Env.HOST):
        self.open_url(url=url)
        return self

    def login_hx(self,username,password):
        self.input_text(self.username, username)
        self.input_text(self.password, password)
        self.click_element(self.login_button)

class hxHomePage(BasePage):
    '''
    登录到首页后，点击效能平台按钮，切换到效能平台
    '''
    def login_to_xiaoneng(self):
        self.click_element(self.xiaoneng_button)
        # self.switch_newest_window(2)
        self.switch_newest_window()

class xnPage(BasePage):
    '''
    到效能平台后，点击更多-禅道按钮，切换到禅道首页
    '''
    def login_to_chandao(self):
        #如果有新版本提示的弹框，则关闭
        # if self.get_element(self.newrelase_popup):
        #     self.click_element(self.newrelase_popup)
        self.get_element(self.xmxiezuo_button)
        self.click_element(self.more_button)
        self.click_element(self.chandao_button)
        # self.switch_newest_window(3)  
        self.switch_newest_window()  
    def oper_login_to_chandao_combined(self,dic):
        LoginPage().open_hx_loginpage()
        LoginPage().login_hx(dic['Account'], dic['Password'])
        hxHomePage().login_to_xiaoneng()
        xnPage().login_to_chandao()


if __name__ == '__main__':
    dic = {'username':'17751002401','password':'Fangjinmei625@'}
    xnPage().oper_login_to_chandao_combined(dic)